package com.example.springbootsecurity.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.springbootsecurity.entity.ShiroUser;
import com.example.springbootsecurity.service.ShiroUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.Subject;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author vicente
 * @since 2022-01-11
 */
@RestController
public class ShiroUserController {

    @Autowired
    private ShiroUserService userService;

    @RequestMapping("/whoim")
    @ResponseBody
    public Object whoIm()
    {
        return SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    @RequestMapping("/testShiro")
    public String testShiro(){
        return "success";
    }

    @RequestMapping("/getUserByName")
    public String getUserByName(String userName){
        ShiroUser user = userService.getUserByName(userName);
        return JSON.toJSONString(user);
    }


    @RequestMapping("/add")
    public String add(){
        System.out.println("add---------------");
        return "add";
    }

    @RequestMapping("/add/open")
    public String open(){
        System.out.println("add open---------------");
        return "add open";
    }

    @RequestMapping("/test/open")
    public String testOpen(){
        System.out.println("testOpen---------------");
        return "testOpen";
    }

    @RequestMapping("/test/close")
    public String testClose(){
        System.out.println("testClose---------------");
        return "testClose";
    }

    @RequestMapping("/delete")
    public String delete(){
        System.out.println("delete---------------");
        return "delete";
    }

    @RequestMapping("/403")
    public String getError(){
        System.out.println("未授权页面---------------");
        return "403";
    }

}
